import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import {getRequest} from "@/api/api";
import {postRequest} from "@/api/api";
import {deleteRequest} from "@/api/api";
import {putRequest} from "@/api/api";
Vue.prototype.postRequest=postRequest
Vue.prototype.putRequest=putRequest
Vue.prototype.getRequest=getRequest
Vue.prototype.deleteRequest=deleteRequest
Vue.config.productionTip = false
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

router.beforeEach((to, from, next) => {
    //to：d到 去哪里
    //from： 从哪里来
    //next
    if(window.sessionStorage.getItem("token")){

        if(!window.sessionStorage.getItem("user")){
            return getRequest("/admin/info").then(resp=>{
                if(resp) {
                    window.sessionStorage.setItem("user", JSON.stringify(resp.data));
                    next();
                }
            })
        }
        next();
    }else{
        next();
    }


})
Vue.use(ElementUI);
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
